#include "devcfg.h"
#include "string.h"


static es_dev_config<DEV_CONFIG> s_dev_config;
static DEV_CONFIG* s_user_cfg;


//设备配置初始化
void dev_config_init()
{
    if(!s_dev_config.init()){
        debug("device config init fail.\r\n");
    }
    s_user_cfg=s_dev_config.get_user_struct();

    //新flash处理
    if(s_dev_config.get_dev_state()!=dev_state_activated){
        //初始化新配置
        for(int i=0;i<STR_LEN;i++){
            s_user_cfg->str1[i]=0;
            s_user_cfg->str2[i]=0;
        }
        s_user_cfg->val=0;
        
        //已激活状态
        s_dev_config.dev_active();		//保存

        debug("device config initilized.\r\n");
    }
    debug("device config read.\r\n");
}


//获取设备配置
DEV_CONFIG* get_dev_config()
{
    return s_user_cfg;
}


//显示设备配置
void view_dev_config()
{
    printf("[device config]\r\n\tstr1:%s\r\n\tstr2:%s\r\n\tval:%d\r\n",
        s_user_cfg->str1,s_user_cfg->str2,s_user_cfg->val);
}


//更新设备配置
void udpate_dev_config()
{
    s_dev_config.update();
}

